<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { GameManager } from './core/GameManager'
import { useGameStore } from './stores/gameStore'

const gameInitialized = ref(false)
const gameStore = useGameStore()

onMounted(async () => {
  try {
    const gameManager = new GameManager()
    await gameManager.init()
    await gameManager.start()
    gameInitialized.value = true
    console.log('游戏启动成功！')
  } catch (error) {
    console.error('游戏启动失败:', error)
  }
})
</script>

<template>
  <div id="app">
    <div id="game-container"></div>
    <div v-if="!gameInitialized" class="loading-screen">
      <div class="loading-content">
        <h2>肉鸽地牢冒险</h2>
        <p>正在加载游戏资源...</p>
        <div class="loading-spinner"></div>
      </div>
    </div>
  </div>
</template>

<style>
#app {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

#game-container {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

.loading-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.loading-content {
  text-align: center;
  color: white;
}

.loading-content h2 {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.loading-content p {
  font-size: 1.2rem;
  margin-bottom: 2rem;
  opacity: 0.9;
}

.loading-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top: 4px solid white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

/* 确保Phaser画布占满整个容器 */
canvas {
  display: block;
  margin: 0;
  padding: 0;
}
</style>
